<?php
class ModelCamdoNhomtaisan extends Model 
{
	private $columns = array(
								'nhomtaisanid',
								'tennhomtaisan',
								'laisuat'
							);
	public function getList($where = "")
	{
		$sql = "Select `cd_nhomtaisan`.* from `cd_nhomtaisan` where 1=1 ".$where;
		$query = $this->db->query($sql);
		return $query->rows;
	}

	public function getItem($nhomtaisanid)
	{
		$sql = "Select * from `cd_nhomtaisan` where nhomtaisanid = '".$nhomtaisanid."'";
		$query = $this->db->query($sql);
		return $query->row;
	}
	
	
	public function insert($data)
	{
		$data['laisuat']=$this->string->toNumber($data['laisuat']);
		$data['trangthai']="active";
		foreach($this->columns as $val)
		{
			if($val!="")
			{
				$field[] = $val;
				$value[] = $this->db->escape($data[$val]);	
			}
		}
		
		$getLastId = $this->db->insertData("cd_nhomtaisan",$field,$value);
				
		return $getLastId;
	}
	
	
	public function update($data)
	{		
		$data['laisuat']=$this->string->toNumber($data['laisuat']);
		foreach($this->columns as $val)
		{
			if($val!="")
			{
				$field[] = $val;
				$value[] = $this->db->escape($data[$val]);	
			}
		}
		
		$where="nhomtaisanid = '".$data['nhomtaisanid']."'";
		$this->db->updateData("cd_nhomtaisan",$field,$value,$where);
	}	
		
	public function updateCol($nhomtaisanid,$col,$val)
	{
		$nhomtaisanid=$this->db->escape(@$nhomtaisanid);
		$col=$this->db->escape(@$col);
		$val=$this->db->escape(@$val);
		$field=array(
						$col
					);
		$value=array(
						$val
					);
					
		$where="nhomtaisanid = '".$nhomtaisanid."'";
		$this->db->updateData("cd_nhomtaisan",$field,$value,$where);
	}
	
	//Xóa nhom
	public function delete($nhomtaisanid)
	{
		$nhomtaisanid=(int)@$nhomtaisanid;
		$where="nhomtaisanid = ".$nhomtaisanid;
		$this->db->deleteData('cd_nhomtaisan',$where);
		
	}
}
?>